const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');
var WxParse = require('../../wxParse/wxParse.js');

Page({
	data: {
		courseName: "", //名称
		enrollnum: "5/50", //报名上限
		courseTime: "05.30-06.05", //上课时间段
		tuition: "1999", //课程学费
		_article: "", //富文本
		cid: 0,
		cname: "",
		is_showgo: true
	},
	onReady: function() {
		if (!app.login()) {
			return;
		}
	},
	onLoad(options) {
		//文章内容
		this.cid = options.id;
		this.getCourseData();
		this.checkenroll();
		var that = this;
		this.setData({
			'cid': that.cid
		})
	},
	getCourseData() { //获取【课程详情】
		var that = this;
		var _content = "";
		http.httpPost(config.get_classese_detail, {
			curriculum_id: that.cid
		}, function(e) {
			that.setData({
				'courseName': e.data.coursename,
				'enrollnum': e.data.timeStr,
				'courseTime': e.data.regisStr,
				'tuition': e.data.tuition,
				// '_article':e.data.content
			});
			_content = e.data.content;
			WxParse.wxParse('article', 'html', _content, that);

		});

	},
	checkenroll() {
		var that = this;
		http.httpPost(config.checkenrollstudent, {
			curriculum_id: that.cid, //订单类型:1=餐饮订单,2=课程订单
		}, function(e) {
			if (e.data) {
				that.is_showgo = false;
				that.setData({
					'is_showgo': false
				})
			}
		})
	},
	clickbtn() {
		wx.showToast({
			title: '该课程已达到报名上限',
			icon: 'none',
			duration: 1000,
			mask: true
		});
	}

})
